package wp.ggt.com.wpview.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by KF on 2016/3/18.
 */
public abstract class CommendAdapter<T> extends BaseAdapter {
    private List<T> datas;
    private Context context;
    private int LayoutId;

    public CommendAdapter(Context context, int LayoutId, List<T> datas) {
        this.datas = datas;
        this.context = context;
        this.LayoutId = LayoutId;
    }

    @Override
    public int getCount() {
        return datas != null ? datas.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = ViewHolder.getContentView(convertView, context, LayoutId);
        setItemData((ViewHolder) convertView.getTag(), (T) getItem(position));
        return convertView;
    }

    public abstract void setItemData(ViewHolder holder, T data);
}
